package com.aurora.source.authority.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aurora.source.R;
import com.aurora.source.authority.adapter.ProcessListAdapter;
import com.aurora.source.authority.adapter.SysAuthListAdapter;
import com.aurora.source.authority.presenter.ExaminePresenter;
import com.aurora.source.authority.view.IExamineView;
import com.aurora.source.base.BaseWhiteToolbarActivity;
import com.aurora.source.source.bean.UserInfoBean;
import com.aurora.source.util.DpPxUtil;
import com.aurora.source.widget.CustomRecyclerView;
import com.aurora.source.widget.flowlayout.FlowLayoutManager;
import com.aurora.source.widget.flowlayout.SpaceItemDecoration;
import com.bumptech.glide.Glide;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 查看授权信息
 */
public class ExamineActivity extends BaseWhiteToolbarActivity<ExaminePresenter> implements IExamineView {

    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.iv_card_just)
    ImageView ivCardJust;
    @BindView(R.id.iv_card_against)
    ImageView ivCardAgainst;
    @BindView(R.id.tv_ID_number)
    TextView tvIDNumber;
    @BindView(R.id.rv_process)
    RecyclerView rvProcess;
    @BindView(R.id.rv_sys_auth)
    CustomRecyclerView rvSysAuth;
    private String userId;
    ProcessListAdapter processListAdapter;
    SysAuthListAdapter sysAuthSelectAdapter;
    @Override
    public ExaminePresenter attach() {
        return new ExaminePresenter(this);
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_examine;
    }

    @Override
    public void initData(@Nullable Bundle bundle) {
        userId = getIntent().getStringExtra("userId");
        Map<String, String> params = new HashMap<>();
        params.put("userId", userId);
        basePresenter.Examine(activity, params, true);
    }


    @Override
    public void initView(Bundle savedInstanceState, View contentView) {
        simpleToolbar.setMainTitle("权限管理-查看");
        simpleToolbar.setLeftVisibility(View.VISIBLE);
        processListAdapter = new ProcessListAdapter();
        sysAuthSelectAdapter = new SysAuthListAdapter();
        rvProcess.setLayoutManager(new FlowLayoutManager());
        rvProcess.setAdapter(processListAdapter);
        rvProcess.addItemDecoration(new SpaceItemDecoration(DpPxUtil.dp2px(this, 5)));
        rvSysAuth.setLayoutManager(new FlowLayoutManager());
        rvSysAuth.setAdapter(sysAuthSelectAdapter);
        rvSysAuth.addItemDecoration(new SpaceItemDecoration(DpPxUtil.dp2px(this, 5)));

    }

    @Override
    public void doBusiness() {

    }

    @Override
    public void onExamineSuccess(UserInfoBean data) {

        processListAdapter.setDataList(data.getUserInfoDTO().getProcessList());
        sysAuthSelectAdapter.setDataList(data.getUserInfoDTO().getSysRoleList2());
        tvNumber.setText(data.getUserInfoDTO().getUserAccount());
        tvName.setText(data.getUserInfoDTO().getUserName());
        tvPhone.setText(data.getUserInfoDTO().getUserMobile());
        Glide.with(getApplicationContext())
                .load(data.getUserInfoDTO().getIdCardImg1())
                .into(ivCardJust);
        Glide.with(getApplicationContext())
                .load(data.getUserInfoDTO().getIdCardImg2())
                .into(ivCardAgainst);
        tvIDNumber.setText(data.getUserInfoDTO().getIdCardNo());

    }

    @Override
    public void onExamineFail(String msg) {
        showToast(msg);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
